package com.power.model.factories
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.IOErrorEvent;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	
	import mx.controls.Alert;

	public class CatetorysFactory extends EventDispatcher
	{
		private var _catetory_url:String ;
		
		private var roomCategorys:Array = [];
		
		private var floorCategorys:Array = [];
		
		private var _xmlloader:URLLoader;
		
		private var parserXML:XML;
		
		public function CatetorysFactory()
		{
			
		}
		public function startLoadedXml(cate_url:String):void
		{
			_catetory_url = cate_url;
			_xmlloader = new URLLoader();
			try{
				_xmlloader.load(new URLRequest(_catetory_url));
				_xmlloader.addEventListener(Event.COMPLETE,loadxmlendHandler);
				_xmlloader.addEventListener(IOErrorEvent.IO_ERROR,ioErrorHandler);
			}catch(e:Error)
			{
				throw new Error("error on load catetroys xml.file");
			}
		}
		private function loadxmlendHandler(e:Event):void
		{
			parserXML = new XML(e.target.data);
			var roomtype:String;
			var floortype:String;
			var roomlen:int = parserXML.roomtype.room.length();
			var floorlen:int = parserXML.floortype.floor.length();
			for(var i:int=0 ;i<roomlen;i++)
			{
				roomtype = parserXML.roomtype.room[i]
				roomCategorys.push(roomtype);
			}
			for(var j:int = 0 ;j<floorlen; j++)
			{
				floortype = parserXML.floortype.floor[j];
				floorCategorys.push(floortype);
			}
			this.dispatchEvent(new Event("ParserCateGeroyEnd"));
		}
		private function ioErrorHandler(e:IOErrorEvent):void
		{
			Alert.show("加载类弄XML出错！");
		}
		private function startParserXML(xml:XML):void
		{
			var tempxml:XML = xml;
		}
		public function getRoomCateGorys():Array
		{
			return roomCategorys;
		}
		public function getFloorCateGorys():Array
		{
			return floorCategorys;
		}
	}
}